const fs = require('fs');
const path = require('path');

const filePath = 'd:\\Users\\zhansiji\\entry\\src\\main\\ets\\commos\\types.ets';

// 读取文件内容
let content = fs.readFileSync(filePath, 'utf8');

// 修复损坏的 id 字段
content = content.replace(/id:\s*\n\s*\$result = \$counter\n\s*\$counter\+\+\n\s*return \$result\n/g, 'id: PLACEHOLDER');

// 重新分配 id
let counter = 1;
content = content.replace(/id:\s*PLACEHOLDER/g, () => {
    return `id: ${counter++}`;
});

// 写回文件
fs.writeFileSync(filePath, content, 'utf8');

console.log(`已成功修复并重新整理 commonEnglishWords 数组的 id，共处理了 ${counter - 1} 个条目`);